#include <iostream> 
#include <vector>
#include <algorithm>
using namespace std;

vector<int> len;
vector< vector<int> > gr;
int MAX = 0;
int f(int ly,int s,int sum){
	cout <<"layer="<< ly << endl;
	if( ly==len.size()-1 ){
		cout << "sum="<< sum << endl;
		if( sum + len[ly] - s > MAX ) MAX = sum;
		return ly;
	}
	for(int i=s; i<len[ly]; i++){
		if( ly==0 ) f(ly+1,gr[ly][i],i+1);
		else f(ly+1,gr[ly][i],sum+len[ly]-i);	
	}	
	return ly;
}

bool cmp(pair<int,int> &p1,pair<int,int> p2){
	return p1.first!=p2.first? p1.first < p2.first : p1.second < p2.second;
}
int main(){
	int n;
	cin >> n;
	pair<int,int> a[n];
	int v1,v2;
	for(int i=0; i<n; i++){
		cin >> v1 >> v2;
		a[i] = make_pair(v1,v2);
	}
	sort(a,a+n,cmp);
	for(int i=0; i<n; i++){
		cout << a[i].first << "-" << a[i].second << " ";
	}
	cout << endl << endl;
	vector<int> begin;
	begin.push_back(0);
	int flag = a[0].first;
	int cnt = 0;
	for(int i=0; i<n; i++){
		if( a[i].first == flag ) cnt++;
		else{
			begin.push_back(i);
			len.push_back(cnt);
			flag = a[i].first;
			cnt = 1;
		}
	}
	len.push_back(cnt);
	for(int i=0; i<len.size(); i++) cout << len[i] << " ";
	cout << endl;
	for(int i=0; i<begin.size(); i++) cout << begin[i] << " ";
	cout << endl;
	
	
	for(int i=0; i<begin.size()-1; i++){
		vector<int> v;
		for(int j=0; j<len[i]; j++){
			int t = a[ begin[i]+j ].second;
			int k = 0;
			for(; k<len[i+1]&&a[ begin[i+1]+k ].second<t; k++);
			v.push_back(k);
		}
		gr.push_back(v);
	}
	

	
	for(int i=0; i<gr.size(); i++){
		for(int j=0; j<gr[i].size(); j++){
			cout << gr[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	f(0,0,0);
	cout << MAX;
	return 0;
}
